/*eslint-disable block-scoped-var, no-redeclare, no-control-regex, no-prototype-builtins*/
"use strict";

var $protobuf = require("protobufjs/minimal");

// Common aliases
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;

// Exported root namespace
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});

$root.b3 = (function() {

    /**
     * Namespace b3.
     * @exports b3
     * @namespace
     */
    var b3 = {};

    b3.OperLog = (function() {

        /**
         * Properties of an OperLog.
         * @memberof b3
         * @interface IOperLog
         * @property {string|null} [key] OperLog key
         * @property {Uint8Array|null} [oldValue] OperLog oldValue
         * @property {Uint8Array|null} [newValue] OperLog newValue
         */

        /**
         * Constructs a new OperLog.
         * @memberof b3
         * @classdesc Represents an OperLog.
         * @implements IOperLog
         * @constructor
         * @param {b3.IOperLog=} [properties] Properties to set
         */
        function OperLog(properties) {
            if (properties)
                for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
                    if (properties[keys[i]] != null)
                        this[keys[i]] = properties[keys[i]];
        }

        /**
         * OperLog key.
         * @member {string} key
         * @memberof b3.OperLog
         * @instance
         */
        OperLog.prototype.key = "";

        /**
         * OperLog oldValue.
         * @member {Uint8Array} oldValue
         * @memberof b3.OperLog
         * @instance
         */
        OperLog.prototype.oldValue = $util.newBuffer([]);

        /**
         * OperLog newValue.
         * @member {Uint8Array} newValue
         * @memberof b3.OperLog
         * @instance
         */
        OperLog.prototype.newValue = $util.newBuffer([]);

        /**
         * Creates a new OperLog instance using the specified properties.
         * @function create
         * @memberof b3.OperLog
         * @static
         * @param {b3.IOperLog=} [properties] Properties to set
         * @returns {b3.OperLog} OperLog instance
         */
        OperLog.create = function create(properties) {
            return new OperLog(properties);
        };

        /**
         * Encodes the specified OperLog message. Does not implicitly {@link b3.OperLog.verify|verify} messages.
         * @function encode
         * @memberof b3.OperLog
         * @static
         * @param {b3.IOperLog} message OperLog message or plain object to encode
         * @param {$protobuf.Writer} [writer] Writer to encode to
         * @returns {$protobuf.Writer} Writer
         */
        OperLog.encode = function encode(message, writer) {
            if (!writer)
                writer = $Writer.create();
            if (message.key != null && message.hasOwnProperty("key"))
                writer.uint32(/* id 1, wireType 2 =*/10).string(message.key);
            if (message.oldValue != null && message.hasOwnProperty("oldValue"))
                writer.uint32(/* id 2, wireType 2 =*/18).bytes(message.oldValue);
            if (message.newValue != null && message.hasOwnProperty("newValue"))
                writer.uint32(/* id 3, wireType 2 =*/26).bytes(message.newValue);
            return writer;
        };

        /**
         * Encodes the specified OperLog message, length delimited. Does not implicitly {@link b3.OperLog.verify|verify} messages.
         * @function encodeDelimited
         * @memberof b3.OperLog
         * @static
         * @param {b3.IOperLog} message OperLog message or plain object to encode
         * @param {$protobuf.Writer} [writer] Writer to encode to
         * @returns {$protobuf.Writer} Writer
         */
        OperLog.encodeDelimited = function encodeDelimited(message, writer) {
            return this.encode(message, writer).ldelim();
        };

        /**
         * Decodes an OperLog message from the specified reader or buffer.
         * @function decode
         * @memberof b3.OperLog
         * @static
         * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
         * @param {number} [length] Message length if known beforehand
         * @returns {b3.OperLog} OperLog
         * @throws {Error} If the payload is not a reader or valid buffer
         * @throws {$protobuf.util.ProtocolError} If required fields are missing
         */
        OperLog.decode = function decode(reader, length) {
            if (!(reader instanceof $Reader))
                reader = $Reader.create(reader);
            var end = length === undefined ? reader.len : reader.pos + length, message = new $root.b3.OperLog();
            while (reader.pos < end) {
                var tag = reader.uint32();
                switch (tag >>> 3) {
                case 1:
                    message.key = reader.string();
                    break;
                case 2:
                    message.oldValue = reader.bytes();
                    break;
                case 3:
                    message.newValue = reader.bytes();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
                }
            }
            return message;
        };

        /**
         * Decodes an OperLog message from the specified reader or buffer, length delimited.
         * @function decodeDelimited
         * @memberof b3.OperLog
         * @static
         * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
         * @returns {b3.OperLog} OperLog
         * @throws {Error} If the payload is not a reader or valid buffer
         * @throws {$protobuf.util.ProtocolError} If required fields are missing
         */
        OperLog.decodeDelimited = function decodeDelimited(reader) {
            if (!(reader instanceof $Reader))
                reader = new $Reader(reader);
            return this.decode(reader, reader.uint32());
        };

        /**
         * Verifies an OperLog message.
         * @function verify
         * @memberof b3.OperLog
         * @static
         * @param {Object.<string,*>} message Plain object to verify
         * @returns {string|null} `null` if valid, otherwise the reason why it is not
         */
        OperLog.verify = function verify(message) {
            if (typeof message !== "object" || message === null)
                return "object expected";
            if (message.key != null && message.hasOwnProperty("key"))
                if (!$util.isString(message.key))
                    return "key: string expected";
            if (message.oldValue != null && message.hasOwnProperty("oldValue"))
                if (!(message.oldValue && typeof message.oldValue.length === "number" || $util.isString(message.oldValue)))
                    return "oldValue: buffer expected";
            if (message.newValue != null && message.hasOwnProperty("newValue"))
                if (!(message.newValue && typeof message.newValue.length === "number" || $util.isString(message.newValue)))
                    return "newValue: buffer expected";
            return null;
        };

        /**
         * Creates an OperLog message from a plain object. Also converts values to their respective internal types.
         * @function fromObject
         * @memberof b3.OperLog
         * @static
         * @param {Object.<string,*>} object Plain object
         * @returns {b3.OperLog} OperLog
         */
        OperLog.fromObject = function fromObject(object) {
            if (object instanceof $root.b3.OperLog)
                return object;
            var message = new $root.b3.OperLog();
            if (object.key != null)
                message.key = String(object.key);
            if (object.oldValue != null)
                if (typeof object.oldValue === "string")
                    $util.base64.decode(object.oldValue, message.oldValue = $util.newBuffer($util.base64.length(object.oldValue)), 0);
                else if (object.oldValue.length)
                    message.oldValue = object.oldValue;
            if (object.newValue != null)
                if (typeof object.newValue === "string")
                    $util.base64.decode(object.newValue, message.newValue = $util.newBuffer($util.base64.length(object.newValue)), 0);
                else if (object.newValue.length)
                    message.newValue = object.newValue;
            return message;
        };

        /**
         * Creates a plain object from an OperLog message. Also converts values to other types if specified.
         * @function toObject
         * @memberof b3.OperLog
         * @static
         * @param {b3.OperLog} message OperLog
         * @param {$protobuf.IConversionOptions} [options] Conversion options
         * @returns {Object.<string,*>} Plain object
         */
        OperLog.toObject = function toObject(message, options) {
            if (!options)
                options = {};
            var object = {};
            if (options.defaults) {
                object.key = "";
                object.oldValue = options.bytes === String ? "" : [];
                object.newValue = options.bytes === String ? "" : [];
            }
            if (message.key != null && message.hasOwnProperty("key"))
                object.key = message.key;
            if (message.oldValue != null && message.hasOwnProperty("oldValue"))
                object.oldValue = options.bytes === String ? $util.base64.encode(message.oldValue, 0, message.oldValue.length) : options.bytes === Array ? Array.prototype.slice.call(message.oldValue) : message.oldValue;
            if (message.newValue != null && message.hasOwnProperty("newValue"))
                object.newValue = options.bytes === String ? $util.base64.encode(message.newValue, 0, message.newValue.length) : options.bytes === Array ? Array.prototype.slice.call(message.newValue) : message.newValue;
            return object;
        };

        /**
         * Converts this OperLog to JSON.
         * @function toJSON
         * @memberof b3.OperLog
         * @instance
         * @returns {Object.<string,*>} JSON object
         */
        OperLog.prototype.toJSON = function toJSON() {
            return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
        };

        return OperLog;
    })();

    b3.Transaction = (function() {

        /**
         * Properties of a Transaction.
         * @memberof b3
         * @interface ITransaction
         * @property {string|null} [txId] Transaction txId
         * @property {string|null} [cId] Transaction cId
         * @property {string|null} [action] Transaction action
         * @property {string|null} [data] Transaction data
         */

        /**
         * Constructs a new Transaction.
         * @memberof b3
         * @classdesc Represents a Transaction.
         * @implements ITransaction
         * @constructor
         * @param {b3.ITransaction=} [properties] Properties to set
         */
        function Transaction(properties) {
            if (properties)
                for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
                    if (properties[keys[i]] != null)
                        this[keys[i]] = properties[keys[i]];
        }

        /**
         * Transaction txId.
         * @member {string} txId
         * @memberof b3.Transaction
         * @instance
         */
        Transaction.prototype.txId = "";

        /**
         * Transaction cId.
         * @member {string} cId
         * @memberof b3.Transaction
         * @instance
         */
        Transaction.prototype.cId = "";

        /**
         * Transaction action.
         * @member {string} action
         * @memberof b3.Transaction
         * @instance
         */
        Transaction.prototype.action = "";

        /**
         * Transaction data.
         * @member {string} data
         * @memberof b3.Transaction
         * @instance
         */
        Transaction.prototype.data = "";

        /**
         * Creates a new Transaction instance using the specified properties.
         * @function create
         * @memberof b3.Transaction
         * @static
         * @param {b3.ITransaction=} [properties] Properties to set
         * @returns {b3.Transaction} Transaction instance
         */
        Transaction.create = function create(properties) {
            return new Transaction(properties);
        };

        /**
         * Encodes the specified Transaction message. Does not implicitly {@link b3.Transaction.verify|verify} messages.
         * @function encode
         * @memberof b3.Transaction
         * @static
         * @param {b3.ITransaction} message Transaction message or plain object to encode
         * @param {$protobuf.Writer} [writer] Writer to encode to
         * @returns {$protobuf.Writer} Writer
         */
        Transaction.encode = function encode(message, writer) {
            if (!writer)
                writer = $Writer.create();
            if (message.txId != null && message.hasOwnProperty("txId"))
                writer.uint32(/* id 1, wireType 2 =*/10).string(message.txId);
            if (message.cId != null && message.hasOwnProperty("cId"))
                writer.uint32(/* id 2, wireType 2 =*/18).string(message.cId);
            if (message.action != null && message.hasOwnProperty("action"))
                writer.uint32(/* id 3, wireType 2 =*/26).string(message.action);
            if (message.data != null && message.hasOwnProperty("data"))
                writer.uint32(/* id 4, wireType 2 =*/34).string(message.data);
            return writer;
        };

        /**
         * Encodes the specified Transaction message, length delimited. Does not implicitly {@link b3.Transaction.verify|verify} messages.
         * @function encodeDelimited
         * @memberof b3.Transaction
         * @static
         * @param {b3.ITransaction} message Transaction message or plain object to encode
         * @param {$protobuf.Writer} [writer] Writer to encode to
         * @returns {$protobuf.Writer} Writer
         */
        Transaction.encodeDelimited = function encodeDelimited(message, writer) {
            return this.encode(message, writer).ldelim();
        };

        /**
         * Decodes a Transaction message from the specified reader or buffer.
         * @function decode
         * @memberof b3.Transaction
         * @static
         * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
         * @param {number} [length] Message length if known beforehand
         * @returns {b3.Transaction} Transaction
         * @throws {Error} If the payload is not a reader or valid buffer
         * @throws {$protobuf.util.ProtocolError} If required fields are missing
         */
        Transaction.decode = function decode(reader, length) {
            if (!(reader instanceof $Reader))
                reader = $Reader.create(reader);
            var end = length === undefined ? reader.len : reader.pos + length, message = new $root.b3.Transaction();
            while (reader.pos < end) {
                var tag = reader.uint32();
                switch (tag >>> 3) {
                case 1:
                    message.txId = reader.string();
                    break;
                case 2:
                    message.cId = reader.string();
                    break;
                case 3:
                    message.action = reader.string();
                    break;
                case 4:
                    message.data = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
                }
            }
            return message;
        };

        /**
         * Decodes a Transaction message from the specified reader or buffer, length delimited.
         * @function decodeDelimited
         * @memberof b3.Transaction
         * @static
         * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
         * @returns {b3.Transaction} Transaction
         * @throws {Error} If the payload is not a reader or valid buffer
         * @throws {$protobuf.util.ProtocolError} If required fields are missing
         */
        Transaction.decodeDelimited = function decodeDelimited(reader) {
            if (!(reader instanceof $Reader))
                reader = new $Reader(reader);
            return this.decode(reader, reader.uint32());
        };

        /**
         * Verifies a Transaction message.
         * @function verify
         * @memberof b3.Transaction
         * @static
         * @param {Object.<string,*>} message Plain object to verify
         * @returns {string|null} `null` if valid, otherwise the reason why it is not
         */
        Transaction.verify = function verify(message) {
            if (typeof message !== "object" || message === null)
                return "object expected";
            if (message.txId != null && message.hasOwnProperty("txId"))
                if (!$util.isString(message.txId))
                    return "txId: string expected";
            if (message.cId != null && message.hasOwnProperty("cId"))
                if (!$util.isString(message.cId))
                    return "cId: string expected";
            if (message.action != null && message.hasOwnProperty("action"))
                if (!$util.isString(message.action))
                    return "action: string expected";
            if (message.data != null && message.hasOwnProperty("data"))
                if (!$util.isString(message.data))
                    return "data: string expected";
            return null;
        };

        /**
         * Creates a Transaction message from a plain object. Also converts values to their respective internal types.
         * @function fromObject
         * @memberof b3.Transaction
         * @static
         * @param {Object.<string,*>} object Plain object
         * @returns {b3.Transaction} Transaction
         */
        Transaction.fromObject = function fromObject(object) {
            if (object instanceof $root.b3.Transaction)
                return object;
            var message = new $root.b3.Transaction();
            if (object.txId != null)
                message.txId = String(object.txId);
            if (object.cId != null)
                message.cId = String(object.cId);
            if (object.action != null)
                message.action = String(object.action);
            if (object.data != null)
                message.data = String(object.data);
            return message;
        };

        /**
         * Creates a plain object from a Transaction message. Also converts values to other types if specified.
         * @function toObject
         * @memberof b3.Transaction
         * @static
         * @param {b3.Transaction} message Transaction
         * @param {$protobuf.IConversionOptions} [options] Conversion options
         * @returns {Object.<string,*>} Plain object
         */
        Transaction.toObject = function toObject(message, options) {
            if (!options)
                options = {};
            var object = {};
            if (options.defaults) {
                object.txId = "";
                object.cId = "";
                object.action = "";
                object.data = "";
            }
            if (message.txId != null && message.hasOwnProperty("txId"))
                object.txId = message.txId;
            if (message.cId != null && message.hasOwnProperty("cId"))
                object.cId = message.cId;
            if (message.action != null && message.hasOwnProperty("action"))
                object.action = message.action;
            if (message.data != null && message.hasOwnProperty("data"))
                object.data = message.data;
            return object;
        };

        /**
         * Converts this Transaction to JSON.
         * @function toJSON
         * @memberof b3.Transaction
         * @instance
         * @returns {Object.<string,*>} JSON object
         */
        Transaction.prototype.toJSON = function toJSON() {
            return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
        };

        return Transaction;
    })();

    b3.Block = (function() {

        /**
         * Properties of a Block.
         * @memberof b3
         * @interface IBlock
         * @property {string|null} [hash] Block hash
         * @property {string|null} [prevBlockHash] Block prevBlockHash
         * @property {Array.<b3.ITransaction>|null} [transactions] Block transactions
         */

        /**
         * Constructs a new Block.
         * @memberof b3
         * @classdesc Represents a Block.
         * @implements IBlock
         * @constructor
         * @param {b3.IBlock=} [properties] Properties to set
         */
        function Block(properties) {
            this.transactions = [];
            if (properties)
                for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
                    if (properties[keys[i]] != null)
                        this[keys[i]] = properties[keys[i]];
        }

        /**
         * Block hash.
         * @member {string} hash
         * @memberof b3.Block
         * @instance
         */
        Block.prototype.hash = "";

        /**
         * Block prevBlockHash.
         * @member {string} prevBlockHash
         * @memberof b3.Block
         * @instance
         */
        Block.prototype.prevBlockHash = "";

        /**
         * Block transactions.
         * @member {Array.<b3.ITransaction>} transactions
         * @memberof b3.Block
         * @instance
         */
        Block.prototype.transactions = $util.emptyArray;

        /**
         * Creates a new Block instance using the specified properties.
         * @function create
         * @memberof b3.Block
         * @static
         * @param {b3.IBlock=} [properties] Properties to set
         * @returns {b3.Block} Block instance
         */
        Block.create = function create(properties) {
            return new Block(properties);
        };

        /**
         * Encodes the specified Block message. Does not implicitly {@link b3.Block.verify|verify} messages.
         * @function encode
         * @memberof b3.Block
         * @static
         * @param {b3.IBlock} message Block message or plain object to encode
         * @param {$protobuf.Writer} [writer] Writer to encode to
         * @returns {$protobuf.Writer} Writer
         */
        Block.encode = function encode(message, writer) {
            if (!writer)
                writer = $Writer.create();
            if (message.hash != null && message.hasOwnProperty("hash"))
                writer.uint32(/* id 1, wireType 2 =*/10).string(message.hash);
            if (message.prevBlockHash != null && message.hasOwnProperty("prevBlockHash"))
                writer.uint32(/* id 2, wireType 2 =*/18).string(message.prevBlockHash);
            if (message.transactions != null && message.transactions.length)
                for (var i = 0; i < message.transactions.length; ++i)
                    $root.b3.Transaction.encode(message.transactions[i], writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim();
            return writer;
        };

        /**
         * Encodes the specified Block message, length delimited. Does not implicitly {@link b3.Block.verify|verify} messages.
         * @function encodeDelimited
         * @memberof b3.Block
         * @static
         * @param {b3.IBlock} message Block message or plain object to encode
         * @param {$protobuf.Writer} [writer] Writer to encode to
         * @returns {$protobuf.Writer} Writer
         */
        Block.encodeDelimited = function encodeDelimited(message, writer) {
            return this.encode(message, writer).ldelim();
        };

        /**
         * Decodes a Block message from the specified reader or buffer.
         * @function decode
         * @memberof b3.Block
         * @static
         * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
         * @param {number} [length] Message length if known beforehand
         * @returns {b3.Block} Block
         * @throws {Error} If the payload is not a reader or valid buffer
         * @throws {$protobuf.util.ProtocolError} If required fields are missing
         */
        Block.decode = function decode(reader, length) {
            if (!(reader instanceof $Reader))
                reader = $Reader.create(reader);
            var end = length === undefined ? reader.len : reader.pos + length, message = new $root.b3.Block();
            while (reader.pos < end) {
                var tag = reader.uint32();
                switch (tag >>> 3) {
                case 1:
                    message.hash = reader.string();
                    break;
                case 2:
                    message.prevBlockHash = reader.string();
                    break;
                case 3:
                    if (!(message.transactions && message.transactions.length))
                        message.transactions = [];
                    message.transactions.push($root.b3.Transaction.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
                }
            }
            return message;
        };

        /**
         * Decodes a Block message from the specified reader or buffer, length delimited.
         * @function decodeDelimited
         * @memberof b3.Block
         * @static
         * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
         * @returns {b3.Block} Block
         * @throws {Error} If the payload is not a reader or valid buffer
         * @throws {$protobuf.util.ProtocolError} If required fields are missing
         */
        Block.decodeDelimited = function decodeDelimited(reader) {
            if (!(reader instanceof $Reader))
                reader = new $Reader(reader);
            return this.decode(reader, reader.uint32());
        };

        /**
         * Verifies a Block message.
         * @function verify
         * @memberof b3.Block
         * @static
         * @param {Object.<string,*>} message Plain object to verify
         * @returns {string|null} `null` if valid, otherwise the reason why it is not
         */
        Block.verify = function verify(message) {
            if (typeof message !== "object" || message === null)
                return "object expected";
            if (message.hash != null && message.hasOwnProperty("hash"))
                if (!$util.isString(message.hash))
                    return "hash: string expected";
            if (message.prevBlockHash != null && message.hasOwnProperty("prevBlockHash"))
                if (!$util.isString(message.prevBlockHash))
                    return "prevBlockHash: string expected";
            if (message.transactions != null && message.hasOwnProperty("transactions")) {
                if (!Array.isArray(message.transactions))
                    return "transactions: array expected";
                for (var i = 0; i < message.transactions.length; ++i) {
                    var error = $root.b3.Transaction.verify(message.transactions[i]);
                    if (error)
                        return "transactions." + error;
                }
            }
            return null;
        };

        /**
         * Creates a Block message from a plain object. Also converts values to their respective internal types.
         * @function fromObject
         * @memberof b3.Block
         * @static
         * @param {Object.<string,*>} object Plain object
         * @returns {b3.Block} Block
         */
        Block.fromObject = function fromObject(object) {
            if (object instanceof $root.b3.Block)
                return object;
            var message = new $root.b3.Block();
            if (object.hash != null)
                message.hash = String(object.hash);
            if (object.prevBlockHash != null)
                message.prevBlockHash = String(object.prevBlockHash);
            if (object.transactions) {
                if (!Array.isArray(object.transactions))
                    throw TypeError(".b3.Block.transactions: array expected");
                message.transactions = [];
                for (var i = 0; i < object.transactions.length; ++i) {
                    if (typeof object.transactions[i] !== "object")
                        throw TypeError(".b3.Block.transactions: object expected");
                    message.transactions[i] = $root.b3.Transaction.fromObject(object.transactions[i]);
                }
            }
            return message;
        };

        /**
         * Creates a plain object from a Block message. Also converts values to other types if specified.
         * @function toObject
         * @memberof b3.Block
         * @static
         * @param {b3.Block} message Block
         * @param {$protobuf.IConversionOptions} [options] Conversion options
         * @returns {Object.<string,*>} Plain object
         */
        Block.toObject = function toObject(message, options) {
            if (!options)
                options = {};
            var object = {};
            if (options.arrays || options.defaults)
                object.transactions = [];
            if (options.defaults) {
                object.hash = "";
                object.prevBlockHash = "";
            }
            if (message.hash != null && message.hasOwnProperty("hash"))
                object.hash = message.hash;
            if (message.prevBlockHash != null && message.hasOwnProperty("prevBlockHash"))
                object.prevBlockHash = message.prevBlockHash;
            if (message.transactions && message.transactions.length) {
                object.transactions = [];
                for (var j = 0; j < message.transactions.length; ++j)
                    object.transactions[j] = $root.b3.Transaction.toObject(message.transactions[j], options);
            }
            return object;
        };

        /**
         * Converts this Block to JSON.
         * @function toJSON
         * @memberof b3.Block
         * @instance
         * @returns {Object.<string,*>} JSON object
         */
        Block.prototype.toJSON = function toJSON() {
            return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
        };

        return Block;
    })();

    return b3;
})();

module.exports = $root;
